"use strict";
cc._RF.push(module, '0ec47oT6AtAco9d/E0ss7B2', 'level_peopleArcheryPeople');
// scripts/levelBundles/level_PeopleArchery/unit/level_peopleArcheryPeople.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var level_PeopleArcheryUnitBase_1 = require("../base/level_PeopleArcheryUnitBase");
var peopleArcheryConst_1 = require("../const/peopleArcheryConst");
var level_peopleArcheryOption_1 = require("./level_peopleArcheryOption");
var level_peopleArcheryBullet_1 = require("./level_peopleArcheryBullet");
var level_peopleArcheryEnemy_1 = require("./level_peopleArcheryEnemy");
var gameEngine_1 = require("../../../engines/gameEngine");
var CsvFileKind_1 = require("../../../engines/libs/CsvFileKind");
var MainRoot_1 = require("../../../Game/MainRoot");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level_peopleArcheryPeople = /** @class */ (function (_super) {
    __extends(level_peopleArcheryPeople, _super);
    function level_peopleArcheryPeople() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        /**  角色形象节点 */
        _this.peopleNode_normal = null;
        // @property({type:cc.Node,tooltip:"魔角色形象节点"})
        // /**  角色形象节点 */
        // peopleNode_mo:cc.Node = null;
        // @property({type:cc.Node,tooltip:"仙角色形象节点"})
        // /**  角色形象节点 */
        // peopleNode_xian:cc.Node = null;
        /**  角色形象节点 */
        _this.cloud_normal = null;
        /**  角色形象节点 */
        _this.cloud_mo = null;
        /**  角色形象节点 */
        _this.cloud_xian = null;
        _this.lbText = null;
        _this.hurtNode = null;
        _this.cutEffect = null;
        _this.addHpNode = null;
        _this.xianDecorate = [];
        _this.moDecorate = [];
        _this.rayNode = null;
        _this.titleNode = null;
        _this.titleSp = [];
        _this.peopleNode = null;
        _this.cloudNode = null;
        /**当前形象 */
        _this.profile = "0";
        /**箭的移动距离 */
        _this._arrowDis = 0;
        /**箭的最小移动距离 */
        _this._minArrowDis = 0;
        /**箭的最大移动距离 */
        _this._maxArrowDis = 0;
        /**子弹数量 */
        _this._bulletNum = 1;
        //每行最大的箭的数量
        _this.maxRowLength = 10;
        //每只箭X的间隔
        _this.arrowXInterval = 50;
        _this.synthesisFlag = false;
        _this.lastShotTime = 0;
        _this.curRoleTime = 0;
        _this.xianTitle = ["羽化成仙", "天界上仙", "大罗金仙"];
        _this.moTitle = ["弃世入魔", "炼狱魔王", "修罗无双"];
        _this.bossTitle = ["小试牛刀", "初露锋芒", "炉火纯青", "孤独求败", "飞升大乘"];
        _this.xianMoIndex = 0;
        _this.bossIndex = 0;
        return _this;
    }
    Object.defineProperty(level_peopleArcheryPeople.prototype, "minArrowDis", {
        /**获取最小攻击距离 */
        get: function () { return this._minArrowDis; },
        /**设置最小攻击距离 */
        set: function (value) { this._minArrowDis = value; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_peopleArcheryPeople.prototype, "maxArrowDis", {
        /**获取最大攻击距离 */
        get: function () { return this._maxArrowDis; },
        /**设置最大攻击距离 */
        set: function (value) { this._maxArrowDis = value; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_peopleArcheryPeople.prototype, "arrowDis", {
        /**获取箭的距离 */
        get: function () { return this._arrowDis; },
        /**设置箭的距离 */
        set: function (value) {
            this._arrowDis = Math.max(this._minArrowDis, value);
            this._arrowDis = Math.min(this._maxArrowDis, value);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_peopleArcheryPeople.prototype, "bulletNum", {
        get: function () { return this._bulletNum; },
        set: function (value) { this._bulletNum = value; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_peopleArcheryPeople.prototype, "initAtk", {
        get: function () {
            return this._atkSpd;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_peopleArcheryPeople.prototype, "atkSpd", {
        /**获取攻速 */
        get: function () {
            var atkSpd = this._atkSpd + this.atkSpdAdd;
            atkSpd = Math.max(atkSpd, this.minAtkSpd);
            atkSpd = Math.min(atkSpd, this.maxAtkSpd);
            return atkSpd;
        },
        /**设置攻速 */
        set: function (atkSpd) {
            this._atkSpd = Math.max(atkSpd, this._minAtkSpd);
            this._atkSpd = Math.min(atkSpd, this._maxAtkSpd);
        },
        enumerable: false,
        configurable: true
    });
    level_peopleArcheryPeople.prototype.bindLevel = function (level) {
        var _this = this;
        _super.prototype.bindLevel.call(this, level);
        var roleData = level.roleData;
        var rPath = roleData["role_path"];
        MainRoot_1.default.frameBundle.load("Img/Game/common/peopleArcheryRole/" + rPath, cc.SpriteFrame, function (err, spf) {
            if (err) {
                console.log("加载角色图片失败");
                return;
            }
            _this.peopleNode_normal.getComponent(cc.Sprite).spriteFrame = spf;
        });
    };
    level_peopleArcheryPeople.prototype.start = function () {
        this.changeProfile("0");
        this.cutEffect.width = 0;
        this.cutEffect.active = false;
        this.xianDecorate.forEach(function (n) {
            n.active = false;
        });
        this.moDecorate.forEach(function (n) {
            n.active = false;
        });
        this.rayNode.active = false;
    };
    level_peopleArcheryPeople.prototype.shotBullet = function () {
        var bulletNum = this.bulletNum;
        var posAry = this.getArrowPos(bulletNum);
        this.peopleNode.getComponent(cc.Animation).play();
        // O1HD.getManagers().soundMgr.playSound("peopleArcherySound/Shoot");
        for (var i = 0; i < this.bulletNum; i++) {
            var bullet = this.level.getOneBullet();
            cc.Tween.stopAllByTarget(bullet);
            var bs = bullet.getComponent(level_peopleArcheryBullet_1.default);
            bs.moveSpd = Number(this.level.peopleArcheryData["arrowMoveSpd"]);
            bs.atk = this.shotAtk;
            bs.shotLeech = this.shotLeech;
            bs.criticalPro = this.criticalPro;
            bs.criticalAddition = this.criticalAddition;
            bs.setMaxDis(this.arrowDis);
            bs.initBullet();
            var posX = this.node.x + posAry[i];
            var tX = this.node.x;
            this.level.oneUnitBindLevel(bs);
            bullet.setPosition(tX, this.node.y + 230);
            bullet.setParent(this.level.unitContent);
            cc.tween(bullet).to(0.2, { x: posX }).start();
        }
    };
    level_peopleArcheryPeople.prototype.shot = function () {
        if (this.curRoleTime - this.lastShotTime >= 1 / this.atkSpd) {
            this.lastShotTime = this.curRoleTime;
            this.shotBullet();
        }
    };
    level_peopleArcheryPeople.prototype.onCollisionEnter = function (other, self) {
        switch (other.tag) {
            case peopleArcheryConst_1.peopleArcheryUnitTag.enemy: {
                // 碰到了敌方
                var os = other.node.getComponent(level_peopleArcheryEnemy_1.default);
                var hp = os.hp;
                os.unitDeath();
                this.unitBeHurt(hp, "1");
                os.redSharkAni();
                if (this.profile == "2") {
                    this.cutAni();
                }
                break;
            }
            case peopleArcheryConst_1.peopleArcheryUnitTag.option: {
                // 碰到了选项
                var os = other.node.getComponent(level_peopleArcheryOption_1.default);
                os.clearGroupOption();
                var oProfile = os.optionType;
                if (this.profile == "0" && oProfile != "0") {
                    this.changeProfile(oProfile);
                }
                var oData = os.data;
                if (!oData) {
                    return;
                }
                var waveData = os.wavaData;
                var oType = waveData.option_Type;
                switch (oType) {
                    case "1": {
                        if (this.profile == "1") {
                            this.showTitle("0");
                        }
                        else {
                            this.showTitle("1");
                        }
                        this.level.parseDataAddPeople(oData);
                        break;
                    }
                    case "2":
                    case "3":
                    case "4":
                    case "5": {
                        var d = os.surviveCatastropheData;
                        var successProAry = d.surviveCatastrophe_option_pro.split("|").map(function (v) {
                            return Number(v);
                        });
                        var successPro = successProAry[os.groupIndex];
                        if (Math.random() < successPro) {
                            this.level.parseDataAddPeople(oData);
                            this.showTitle("4");
                        }
                        else {
                            this.rayAni();
                            this.showTitle("5");
                        }
                        break;
                    }
                    default: {
                        this.level.parseDataAddPeople(oData);
                        break;
                    }
                }
                this.level.curWave++;
                os.unitDeath();
                break;
            }
        }
    };
    level_peopleArcheryPeople.prototype.update = function (dt) {
        //如果游戏已经暂停则直接return
        this.refrenshText();
        if (this.level.gamePauseFlag) {
            return;
        }
        _super.prototype.update.call(this, dt);
        this.curRoleTime += dt;
        this.shot();
    };
    level_peopleArcheryPeople.prototype.refrenshText = function () {
        // this.lbText.string = `血量\n${this.hp}\n攻速\n${this.atkSpd}\n攻击力\n${this.atk}\n永久攻击\n${O1HD.getManagers().peopleArcheryManager.getData().atkAddition}`;
        this.lbText.string = "" + this.hp;
    };
    /**
     * 获取箭的位置
     * @param length 箭的数量
     * @returns 箭的位置
     */
    level_peopleArcheryPeople.prototype.getArrowPos = function (length) {
        var posAry = [];
        var rowCount = 0;
        rowCount = length; //(length % this.maxRowLength == 0) ? this.maxRowLength : length % this.maxRowLength;
        var interval = rowCount % 2 == 0 ? this.arrowXInterval / 2 : 0;
        var halfLength = Math.floor(rowCount / 2);
        if (rowCount % 2 != 0) {
            posAry.push(0);
        }
        for (var j = 0; j < halfLength; j++) {
            var index = j + 1;
            var oneVecX = index * this.arrowXInterval - interval;
            var twoVecX = -index * this.arrowXInterval + interval;
            posAry.push(oneVecX);
            posAry.unshift(twoVecX);
        }
        return posAry;
    };
    level_peopleArcheryPeople.prototype.unitDeath = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                // this.level.gameFail();
                // if(this.lastWaveFlag){
                // 打开获得修为界面
                this.level.openMoneyPage(false);
                _super.prototype.unitDeath.call(this);
                return [2 /*return*/];
            });
        });
    };
    level_peopleArcheryPeople.prototype.unitDestroy = function () {
        this.peopleNode.active = false;
    };
    level_peopleArcheryPeople.prototype.alive = function () {
        this.isDeath = false;
        this.node.getComponent(cc.Collider).enabled = true;
        this.peopleNode.active = true;
        this.node.opacity = 255;
        this.level.parseDataAddPeople({ param_type: "0", option_param: "1000" });
        // this.hp = Math.min(Number(this.level.peopleArcheryData["initHp"]),this.maxHp);
    };
    level_peopleArcheryPeople.prototype.unitBeHurtAni = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    /**
     * 更改角色皮肤
     * @param skinId 皮肤id
     */
    level_peopleArcheryPeople.prototype.changeRoleSkin = function (skinId) {
        if (this.peopleNode) {
            this.peopleNode.active = false;
        }
        if (this.cloudNode) {
            this.cloudNode.active = false;
        }
        switch (skinId) {
            case "0": {
                this.peopleNode = this.peopleNode_normal;
                this.cloudNode = this.cloud_normal;
                break;
            }
            case "1": {
                // this.peopleNode = this.peopleNode_xian;
                this.cloudNode = this.cloud_xian;
                break;
            }
            case "2": {
                // this.peopleNode = this.peopleNode_mo;
                this.cloudNode = this.cloud_mo;
                break;
            }
        }
        this.peopleNode.active = true;
        this.cloudNode.active = true;
    };
    /**
     * 更改角色类型
     * @param profileType 0 普通 1仙 2魔
     */
    level_peopleArcheryPeople.prototype.changeProfile = function (profileType) {
        this.profile = profileType;
        this.changeRoleSkin(profileType);
        switch (profileType) {
            case "0": {
                this.xianDecorate.forEach(function (n) {
                    n.active = false;
                });
                this.moDecorate.forEach(function (n) {
                    n.active = false;
                });
                break;
            }
            case "1": {
                this.xianDecorate.forEach(function (n) {
                    n.active = true;
                });
                break;
            }
            case "2": {
                this.moDecorate.forEach(function (n) {
                    n.active = true;
                });
                break;
            }
        }
    };
    level_peopleArcheryPeople.prototype.cutAni = function () {
        cc.Tween.stopAllByTarget(this.cutEffect);
        this.cutEffect.active = true;
        this.cutEffect.width = 0;
        this.cutEffect.opacity = 255;
        cc.tween(this.cutEffect).to(0.1, { width: 320 }).to(0.1, { opacity: 0 }).start();
    };
    level_peopleArcheryPeople.prototype.addHpAni = function () {
        this.addHpNode.active = true;
        var ani = this.addHpNode.getComponent(cc.Animation);
        ani.play();
        ani.on('finished', this.onAddHpFinished, this);
    };
    level_peopleArcheryPeople.prototype.onAddHpFinished = function () {
        this.addHpNode.active = false;
    };
    level_peopleArcheryPeople.prototype.addOneWeapon = function (weaponId) {
        _super.prototype.addOneWeapon.call(this, weaponId);
        var data = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryMagicWeapon, weaponId);
        var can_synthesis_id = data["can_synthesis_id"];
        var synthesisId = data["synthesis_id"];
        if (can_synthesis_id && synthesisId && !this.synthesisFlag) {
            if (this._weapons.includes(can_synthesis_id)) {
                this.level.roleAddWeapon(synthesisId);
                this.synthesisFlag = true;
                this.level.openSynthPage(synthesisId, can_synthesis_id, weaponId);
            }
        }
    };
    level_peopleArcheryPeople.prototype.getWeapons = function () {
        return this._weapons;
    };
    /**雷劈动画 */
    level_peopleArcheryPeople.prototype.rayAni = function () {
        var _this = this;
        this.rayNode.active = true;
        var ani = this.rayNode.getComponent(cc.Animation);
        ani.play("animation");
        ani.on("finished", function () {
            _this.peopleNode_normal.color = cc.color(50, 50, 50);
            cc.tween(_this.peopleNode_normal).delay(1).call(function () {
                _this.peopleNode_normal.color = cc.color(255, 255, 255);
            }).start();
            _this.rayNode.active = false;
        });
    };
    /**
     * 展示称号
     * @param titleType 称号类型 0：仙 1：魔 2：boss 3：法宝 4 渡劫成功 5渡劫失败
     * */
    level_peopleArcheryPeople.prototype.showTitle = function (titleType) {
        var spf = null;
        var titleNode = cc.instantiate(this.titleNode);
        var sp = titleNode.getComponent(cc.Sprite);
        var lb = titleNode.getChildByName("lbTitle").getComponent(cc.Label);
        var chat = "";
        switch (titleType) {
            case "0": {
                spf = this.titleSp[0];
                if (this.xianMoIndex >= this.xianTitle.length) {
                    this.xianMoIndex = this.xianTitle.length - 1;
                }
                chat = this.xianTitle[this.xianMoIndex];
                this.xianMoIndex++;
                break;
            }
            case "1": {
                spf = this.titleSp[1];
                if (this.xianMoIndex >= this.moTitle.length) {
                    this.xianMoIndex = this.moTitle.length - 1;
                }
                chat = this.moTitle[this.xianMoIndex];
                this.xianMoIndex++;
                break;
            }
            case "2": {
                spf = this.titleSp[0];
                if (this.bossIndex >= this.bossTitle.length) {
                    this.bossIndex = this.bossTitle.length - 1;
                }
                chat = this.bossTitle[this.bossIndex];
                this.bossIndex++;
                break;
            }
            case "3": {
                spf = this.titleSp[0];
                break;
            }
            case "4": {
                if (this.profile == "1") {
                    spf = this.titleSp[0];
                }
                else {
                    spf = this.titleSp[1];
                }
                chat = "渡劫成功";
                gameEngine_1.default.getManagers().soundMgr.playSound("peopleArcherySound/Door");
                break;
            }
            case "5": {
                spf = this.titleSp[2];
                chat = "渡劫失败";
                gameEngine_1.default.getManagers().soundMgr.playSound("peopleArcherySound/RedDoor");
                break;
            }
        }
        sp.spriteFrame = spf;
        lb.string = chat;
        titleNode.setParent(this.node);
        titleNode.active = true;
        titleNode.zIndex = 1000;
        titleNode.scale = 0;
        cc.tween(titleNode).to(0.2, { scale: 1 }, { easing: cc.easing.backOut }).delay(2).to(0.5, { opacity: 0 }).call(function () {
            titleNode.destroy();
            titleNode.removeFromParent();
        }).start();
    };
    __decorate([
        property({ type: cc.Node, tooltip: "普通角色形象节点" })
    ], level_peopleArcheryPeople.prototype, "peopleNode_normal", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "普通云节点" })
    ], level_peopleArcheryPeople.prototype, "cloud_normal", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "魔云节点" })
    ], level_peopleArcheryPeople.prototype, "cloud_mo", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "仙云节点" })
    ], level_peopleArcheryPeople.prototype, "cloud_xian", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "text文本" })
    ], level_peopleArcheryPeople.prototype, "lbText", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "受伤图片" })
    ], level_peopleArcheryPeople.prototype, "hurtNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "刀光特效" })
    ], level_peopleArcheryPeople.prototype, "cutEffect", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "回血动画节点" })
    ], level_peopleArcheryPeople.prototype, "addHpNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "仙角色形象装饰" })
    ], level_peopleArcheryPeople.prototype, "xianDecorate", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "魔角色形象装饰" })
    ], level_peopleArcheryPeople.prototype, "moDecorate", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "雷节点" })
    ], level_peopleArcheryPeople.prototype, "rayNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "称号节点" })
    ], level_peopleArcheryPeople.prototype, "titleNode", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "标题图片" })
    ], level_peopleArcheryPeople.prototype, "titleSp", void 0);
    level_peopleArcheryPeople = __decorate([
        ccclass
    ], level_peopleArcheryPeople);
    return level_peopleArcheryPeople;
}(level_PeopleArcheryUnitBase_1.default));
exports.default = level_peopleArcheryPeople;

cc._RF.pop();